//============================================================================
// Name        : numerico.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <fstream>
#include <math.h>
using namespace std;

static float L = 1;
static float A = 0.83;
static float g = 9.81;
static float k = 0.07;


float f(float y){
	return (-g * sin(y) / L);
}


float rungeKutta1(float y, float v){

	float q1;

	q1 = k * f(y);


	return (v + q1);

}

float rungeKutta2(float y,float v){

	float q1;

	q1 = k * (v + k/2);

	return (y + q1);

}

float predictorY(float y,float v){
	return y + (k*v) + (((k*k)/2)*f(y));
}

//float predictorV(float y,float v){
//	return v + k/2 ( f(y) + f(YProx) );
//}

float newmark1(float y,float v){
	float Yprox = predictorY(y,v);
	return y + k*v + (( (k*k)/4 ) *  ( f(y) + f(Yprox)));
}

float newmark2(float y,float v){
	float Yprox = predictorY(y,v);
	return v + k/2 * (f(y) + f(Yprox));
}


//float predictorY(float y,float v){
//	return y + (k*v) + ( (k*k) * (0.25) * f(y) );
//}
//
//float predictorV(float y,float v){
//	return v + ( (0.5) * k * f(y) );
//}
//
//float newmark1(float y,float v){
////	float Yprox = predictorY(y,v);
//	return predictorY(y,v) + ( (k*k) * (0.25) * f(y) );
//}
//
//float newmark2(float y,float v){
////	float Yprox = predictorY(y,v);
//	return predictorV(y,v) + ( k * (0.5) * f(y) );
//}



int main (){

	float y = A; //condicion inicial
	float v = 0; //cond inicial sobre la derivada
	int N = 250;
	float aux;
	ofstream arch ("newmark.txt");

	for (int i=0; i<N; i++){

//		arch<<i*k<<endl;
		arch<<y<<endl;
		aux = y;
		y = newmark1(y,v);
		v = newmark2(aux,v);
//
//		y = predictorY(y,v);
//		v = predictorV(y,v);

//		v = rungeKutta1(y,v);
//		y = rungeKutta2(y,v);


	}

	arch.close();

	return 0;
}
